package com.yc.controller;

import com.yc.domain.JsonModel;
import com.yc.service.BrowsingHistoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Tag(name = "浏览历史API",description = "浏览历史相关的接口")
@RestController
@RequestMapping("/history")
public class BrowsingHistoryController {

    @Autowired
    private BrowsingHistoryService browsingHistoryService;

    @Operation(summary = "增加浏览记录",description = "记录用户id和事务id")
    @PostMapping("/add")
    public JsonModel addBrowsingHistory(@RequestParam String userId, @RequestParam Integer fid) {
        boolean b = browsingHistoryService.addBrowsingHistory(userId, fid);

        if (b) {

            return JsonModel.ok();
        } else {
            return JsonModel.err("添加失败");
        }
    }

    @Operation(summary = "获取浏览历史",description = "获取最近5条浏览记录")
    @GetMapping("/get")
    public JsonModel getBrowsingHistory(@RequestParam String userId) {

        List<String> browsingHistory = browsingHistoryService.getBrowsingHistory(userId);
        if(browsingHistory!=null){

            return JsonModel.ok().setData(browsingHistory);
        }else {
           return JsonModel.err("获取失败");
        }
    }
}